﻿using Abp.Application.Services.Dto;
using shenghua.Order.Orders.Median;
using shenghua.Payment.Payments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Order.Orders.Dto
{
    public class OrderDto: EntityDto
    {
        public string OrderNumber { get; set; }
        public List<OrderDetailDto> Details { get; set; }
        public OrderInfoDto Info { get; set; }
        public OrderMemberInfoDto MemberInfo { get; set; }
        public OrderShipInfoDto ShipInfo { get; set; }
        public OrderEvaluateInfoDto EvaluateInfo { get; set; }
        public OrderPaymentInfoDto PaymentInfo { get; set; }

        public OrderDto(Order order, List<OrderDetail> orderDetails)
        {
            OrderNumber = order.OrderNumber;
            Details = orderDetails.Select(r => new OrderDetailDto(r)).ToList();
            Info = new OrderInfoDto
            {
                CommodityTotalAmount = order.Info.CommodityTotalAmount,
                CommodityTotalCount = order.Info.CommodityTotalCount,
                TotalAmount = order.Info.TotalAmount,
                CouponAmount = order.Info.CouponAmount,
                CouponProfile = order.Info.CouponProfile,
                CouponId = order.Info.CouponId,
                XPAmount = order.Info.XPAmount,
                BounsXPValue = order.Info.BounsXPValue,
                FreightAmount = order.Info.FreightAmount,
                Subject = order.Info.Subject,
                Description = order.Info.Description,
                Status = order.Info.Status,
                CreationTime = order.Info.CreationTime,
                Remark = order.Info.Remark,
                AdminRemark = order.Info.AdminRemark,
                AdjustmentAmount = order.Info.AdjustmentAmount
            };
            MemberInfo = new OrderMemberInfoDto
            {
                Id = order.MemberInfo.Id,
                UserName = order.MemberInfo.UserName
            };
            ShipInfo = new OrderShipInfoDto
            {
                ExpressName =  order.ShipInfo.ExpressName,
                PersonName = order.ShipInfo.PersonName,
                PhoneNumber = order.ShipInfo.PhoneNumber,
                Address = order.ShipInfo.Address,
                ShipStatus = order.ShipInfo.ShipStatus,
                Province = order.ShipInfo.Province,
                City = order.ShipInfo.City,
                County = order.ShipInfo.County,
                DetailedAddress = order.ShipInfo.DetailedAddress,
                ShippingTemplateId = order.ShipInfo.ShippingTemplateId
            };
            EvaluateInfo = new OrderEvaluateInfoDto
            {
                RateValue = order.EvaluateInfo.RateValue,
                Description = order.EvaluateInfo.Description,
                EvaluateStatus = order.EvaluateInfo.EvaluateStatus,
                Pictures = order.EvaluateInfo.Pictures.Items,
                EvaluateTime = order.EvaluateInfo.EvaluateTime

            };
            PaymentInfo = new OrderPaymentInfoDto
            {
                PaymentType = order.PaymentInfo.PaymentType,
                PaymentMethod = order.PaymentInfo.PaymentMethod,
                TradeNumber = order.PaymentInfo.TradeNumber,
                PaymentStatus = order.PaymentInfo.PaymentStatus
            };
        }
    }

    public class OrderInfoDto
    {
        public double TotalAmount { get; set; }
        public double AdjustmentAmount { get; set; }
        public double CommodityTotalAmount { get; set; }
        public int CommodityTotalCount { get; set; }
        public double CouponAmount { get; set; }
        public string CouponProfile { get; set; }
        public int? CouponId { get; set; }
        public double XPAmount { get; set; }
        public int BounsXPValue { get; set; }
        public double FreightAmount { get; set; }
        public string Subject { get; set; }
        public string Description { get; set; }
        public OrderStatus Status { get; set; }
        public DateTime CreationTime { get; set; }
        public string Remark { get; set; }
        public string AdminRemark { get; set; }
    }

    public class OrderMemberInfoDto
    {
        public long Id { get; set; }
        public string UserName { get; set; }
    }

    public class OrderShipInfoDto
    {
        public string ExpressName { get; set; }
        public string PersonName { get; set; }
        public string PhoneNumber { get; set; }
        public string Address { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string County { get; set; }
        public string DetailedAddress { get; set; }
        public int ShippingTemplateId { get; set; }
        public OrderShipStatus ShipStatus { get; set; }
    }

    public class OrderEvaluateInfoDto
    {
        public double RateValue { get; set; }
        public string Description { get; set; }
        public OrderEvaluateStatus EvaluateStatus { get; set; }
        public List<string> Pictures { get; set; }
        public DateTime EvaluateTime { get; set; }
    }

    public class OrderPaymentInfoDto
    {
        public PaymentType PaymentType { get; set; }
        public PaymentMethod? PaymentMethod { get; set; }
        public string TradeNumber { get; set; }
        public OrderPaymentStatus PaymentStatus { get; set; }
    }

    public class OrderDetailDto
    {
        public int CommodityId { get; set; }
        public int? ShoppingOptionId { get; set; }
        public string CommodityName { get; set; }
        public string CommodityPicture { get; set; }
        public int Count { get; set; }
        public double Price { get; set; }
        public int XPValue { get; set; }
        public double OriginalPrice { get; set; }
        public double TotalAmount { get; set; }
        public Dictionary<string, string> ShoppingOptionParameters { get; set; }

        public OrderDetailDto(OrderDetail orderDetail)
        {
            CommodityId = orderDetail.CommodityId;
            ShoppingOptionId = orderDetail.ShoppingOptionId;
            CommodityName = orderDetail.CommodityName;
            CommodityPicture = orderDetail.CommodityPicture;
            Count = orderDetail.Count;
            Price = orderDetail.Price;
            XPValue = orderDetail.XPValue;
            OriginalPrice = orderDetail.OriginalPrice;
            TotalAmount = orderDetail.TotalAmount;
            ShoppingOptionParameters = orderDetail.ShoppingOptionParameters;
        }
    }
}
